# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>

pkgname=cue
pkgver=0.6.0
pkgrel=1
pkgdesc="Validate and define text-based and dynamic configuration"
arch=('loong64' 'x86_64')
url="https://cuelang.org/"
license=('Apache')
makedepends=('go')
depends=('glibc')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/cue-lang/cue/archive/v${pkgver}.tar.gz")
sha512sums=('bd1b5e6d063e0b6317d0abeacd3340009c454b5a03e7edb21381d7e469c566ac73ecf6096ccb5f4cb8643d7f3d98278bda1e39ff80209015463a3d72126bccb0')

build() {
  cd "${pkgname}-${pkgver}/cmd/cue/"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  go build -ldflags "-s -w -linkmode=external -X cuelang.org/go/cmd/cue/cmd.version=${pkgver}" -v .
  chmod +x cue
}

# check() {
#   cd "${pkgname}-${pkgver}"
#   go test -v ./...
# }

package() {
  cd "${pkgname}-${pkgver}/cmd/cue/"
  install -Dsm755 ./cue "${pkgdir}/usr/bin/cue"

  # build bash completions
  mkdir -p "${pkgdir}/usr/share/bash-completion/completions"
  ./cue completion bash  > "${pkgdir}/usr/share/bash-completion/completions/${pkgname}"

  # build zsh completions
  mkdir -p "${pkgdir}/usr/share/zsh/site-functions"
  ./cue completion zsh > "${pkgdir}/usr/share/zsh/site-functions/_${pkgname}"
}
